package workspace.test

object t1 {
  def main(args: Array[String]): Unit = {
    var score = 10
    // if-else if-else
    if (score < 60) {
      print("不及格")
    } else if (score >= 60 & score <= 80) {
      print("一般")
    } else {
      print("优秀")
    }
    // 循环
    // while
    while (score < 100) {
      println(score)
      score = score + 20
    }
    println("-*-" * 20)
    // do-while
    do {
      println(score)
      score = score - 10
    } while (score > 30)
    println("-*-" * 20)
    // for
    var a = 0
    for (a <- 1 to 10) {
      println(a)
    }
    //  Range 可以是一个数字区间表示 i to j ，或者 i until j。左箭头 <- 用于为变量 x 赋值。
    //    for( var x <- Range ){
    //       statement(s);
    //    }
    for (a <- 1 until 10) {
      println(a)
    }

    // for 循环集合
    val box = List(1, 2, 3, 4)
    for (i <- box) {
      println(i)
      if (i / 2 == 1) {
        // for 循环过滤
        print(i)
      }
    }
    //
    val test = List(1, 2, 3, 4, 5, 6, 7, 6)
    var x = for {
      a <- test
      if a < 3; if a < 8
    } yield a
    
    println(x)
  }
}